import { defineStore } from 'pinia'
import { ref } from 'vue'
import { fetchUsers, createUser } from '../api/user'

export const useUserStore = defineStore('user', () => {
  const users = ref<any[]>([])

  const loadUsers = async () => {
    users.value = await fetchUsers()
  }

  const addUser = async (user: any) => {
    const newUser = await createUser(user)
    users.value.push(newUser)
  }

  return { users, loadUsers, addUser }
})